/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.filter;

import java.math.BigDecimal;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author joao
 */
public class PercentualConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        BigDecimal retorno = new BigDecimal(0);
        
        if (!(value.equals(""))) {
            String peso = value;
            String somenteNumero = peso.replace("%", "").replace(",",".");
            retorno = new BigDecimal(somenteNumero);
        }
        return retorno;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String peso = value.toString();
        peso = peso + "%";
        return peso;
    }
}
